from flask import Flask, request, jsonify

app = Flask(__name__)


@app.route('/', methods=["GET", "POST"])
def predict():
    hphm = getpara('hphm')
    hpzl = getpara('hpzl')
    if hphm is None or hpzl is None:
        return jsonify({'status': 'fail', 'data': 'parameter error'})
    return jsonify({'status': 'ok', 'data': f'Hello, {hphm}:{hpzl}!'})


@app.route('/', methods=["GET", "POST"])
def tast():
    return jsonify({'status': 'ok', 'data': 'Hello2!'})


def getpara(key):
    if request.method == "POST":
        if key in request.form:
            value = request.form[key]
        else:
            value = None
    else:
        value = request.args.get(key)
    return value

app.run(port=5001)